<template>
  <Menu class="menu" v-show="showMenu" :active-name="activeName">
    <Submenu :name="m.name" v-for="(m, mi) in menus" :key="'menu' + mi">
      <template #title>
        <Icon :type="m.icon" />
        {{ m.text }}
      </template>
      <div v-if="m.menuItem">
        <MenuItem
          v-for="(mitem, i) in m.child"
          :key="'menu-item' + i"
          :name="mitem.name"
          @click="openPage(mitem.name, mitem.text)"
          >{{ mitem.text }}</MenuItem
        >
      </div>
    </Submenu>
  </Menu>
</template>
<script>
export default {
  data() {
    return {
      activeName: "/admin-index/adminlist",
      menus: [
        {
          name: "/admin-index",
          text: "管理员",
          icon: "md-person",
          menuItem: true,
          child: [
            {
              name: "/admin-index/adminlist",
              text: "账户列表",
            },
          ],
        },
        {
          name: "/admin-index/gcate",
          text: "商品信息",
          icon: "ios-basket",
          menuItem: true,
          child: [
            {
              name: "/admin-index/gcate",
              text: "商品分类",
            },
            {
              name: "/admin-index/goods",
              text: "商品信息",
            },
            {
              name: "/admin-index/orderlist",
              text: "订单管理",
              icon: "ios-cube",
              menuItem: true,
              child: [
                {
                  name: "/admin-index/orderlist",
                  text: "全部订单",
                },
              ],
            },
          ],
        },
        {
          name: "/media",
          text: "多媒体",
          icon: "md-aperture",
          menuItem: true,
          child: [
            {
              name: "/admin-index/bannerlist",
              text: "轮播图管理",
            },
            {
              name: "/admin-index/adver",
              text: "广告管理",
            },
            {
              name: "/admin-index/noticlist",
              text: "通知管理",
            },
          ],
        },
        {
          name: "/admin-index/fundlist",
          icon: "ios-paper",
          text: "资金流水",
          menuItem: true,
          child: [
            {
              name: "/admin-index/fundlist",
              text: "资金流水",
            },
          ],
        },
      ],
    };
  },
  computed: {
    showMenu() {
      if (this.$store.state.routerIndex == 0) {
        return false;
      } else {
        return true;
      }
    },
  },
  methods: {
    // changeMenuItem(name) {
    //   this.$store.commit("addRouterMenuItem", {
    //     name: name,
    //     path: name,
    //   });
    // },
    openPage(name, text) {
      this.$store.commit("addRouterMenuItem", {
        name: text,
        path: name,
      });
    },
  },
};
</script>

<style scoped>
.menu {
  min-height: calc(100vh - 50px);
  min-width: 200px;
  position: fixed;
  left: 0;
  top: 50px;
  z-index: 99;
}
</style>